package com.itheima.resolver;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.itheima.constant.MessageConstant;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

public class MyExceptionResolver implements HandlerExceptionResolver{

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ModelAndView mv = new ModelAndView();
        FastJsonJsonView view = new FastJsonJsonView();
        Map<String, Object> attributes = new HashMap<>();
        attributes.put("flag", false);
        attributes.put("message",MessageConstant.DELETE_CHECKITEM_FAIL);
        view.setAttributesMap(attributes);
        mv.setView(view);
        return mv;
    }
}
